
package com.example.main.Conditional.Conditional;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class TestConditional implements Condition {
    
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        System.out.println("类元数据---->:" + metadata.toString());
        System.out.println("条件上下文---->:" + context.toString());
        // 如果ioc容器中有test1实例，我就注册当前类到容器中
        if (context.getRegistry().containsBeanDefinition("test1")) {
            System.out.println("------容器中存在test1实例,当前类注册到容器中-------");
            return true;
        }
        System.out.println("------容器中不存在test1实例,当前类不注册到容器中-------");
        return false;
    }
}